home *** CD-ROM | disk | FTP | other *** search
/ Flash MX Savvy / FlashMX Savvy.iso / pc / WIN / UltraDev / UltraDev_Trial.exe / Disk1 / data1.cab / Configuration_En / Commands / rename set.js < prev    next >
Encoding:
JavaScript  |  2000-12-11  |  3.0 KB  |  113 lines

  1. // Copyright 2000 Macromedia, Inc. All rights reserved.
  2.  
  3. //*************** GLOBALS *****************
  4. var FILE_CONFIG_PATH = dw.getConfigurationPath();
  5. var FILE_CUSTOM_SET = FILE_CONFIG_PATH + "/Menus/Custom Sets";
  6.  
  7. //******************* API **********************
  8. function commandButtons()
  9. {
  10.    return new Array( BTN_OK,  "cmdOK()"
  11.                    , BTN_Cancel, "cmdCancel()");
  12. }
  13.  
  14. function cmdOK()
  15. {
  16.   var newSetName, facSetArray = new Array(), custSetArray = new Array();
  17.   var canWrite = true;
  18.   var oldFileName = MM.commandArgument;
  19.   
  20.   if (getExtension(oldFileName) != "xml")
  21.     oldFileName += ".xml";
  22.   newSetName = document.renameSetNameField.getAttribute("value");
  23.   if (newSetName.lastIndexOf(".xml") != newSetName.length-4) 
  24.     newSetName += ".xml";
  25.   if (isSet(newSetName, "factory"))   // check to see if name used by factory set
  26.   {
  27.     alert(errMsg(MSG_NameUsedByFactorySet, newSetName));
  28.     canWrite = false;
  29.   }
  30.   else if (isSet(newSetName, "custom"))
  31.   { 
  32.     if (oldFileName == newSetName)
  33.     {
  34.       alert(MSG_SetNameIsTheSame);
  35.       canWrite = false;
  36.     }
  37.     else if (!confirm(errMsg(MSG_ShortcutSetAlreadyExists,newSetName)))
  38.       canWrite = false;
  39.   }
  40.   if (canWrite)
  41.   {
  42.     if (!DWfile.copy(FILE_CUSTOM_SET +"/"+ oldFileName, FILE_CUSTOM_SET+"/"+newSetName))
  43.       alert(errMsg(MSG_InvalidFileNameCannotSave, newSetName));
  44.     else
  45.     {
  46.       DWfile.remove(FILE_CUSTOM_SET +"/"+ oldFileName);
  47.       MM.commandReturnValue = getSimpleName(newSetName);
  48.       window.close();
  49.     }
  50.   }
  51. }
  52.  
  53. function cmdCancel()
  54. {
  55.   window.close();
  56. }
  57. //***************** LOCAL FUNCTIONS  ******************
  58.  
  59. function initializeUI()
  60.   var origSetName; // orig Set Name should be passed in 
  61.   
  62.   origSetName = MM.commandArgument;
  63.   document.renameSetNameField.setAttribute("value", origSetName);
  64.   document.renameSetNameField.focus();
  65.   document.renameSetNameField.select();
  66. }
  67.  
  68. function getCustomSetList(setType)
  69. {
  70.   var fileObj, filterFunction;
  71.   fileObj = new File(FILE_CUSTOM_SET);
  72.   if (setType == "factory")
  73.     filterFunction =  new Function("x", "return (x.isFile()) && (x.getAttributes() == 'R') && (x.getExtension()== 'xml');");
  74.   else
  75.     filterFunction =  new Function("x", "return (x.isFile()) && (x.getAttributes() != 'R') && (x.getExtension()== 'xml');");
  76.   return fileObj.listFolder(filterFunction);
  77. }
  78.  
  79. function isSet(setName, setType)
  80. {
  81.   var facSetArray = new Array(), i, retVal = false;
  82.   facSetArray = getCustomSetList(setType);
  83.   for (i=0; i<facSetArray.length; i++)
  84.   {
  85.     if (facSetArray[i] == setName)
  86.     {
  87.       retVal = true;
  88.       break;
  89.     }
  90.   }
  91.   return retVal;
  92. }
  93.  
  94. function getExtension(fileName)
  95. {
  96.   var retVal = "", index;
  97.     
  98.   index = fileName.lastIndexOf(".");
  99.   if (index != -1)
  100.     retVal = fileName.substring(index+1);
  101.   return retVal;
  102. }
  103.  
  104. function getSimpleName(fileName)
  105. {
  106.   var index; retVal = fileName;
  107.   
  108.   index = fileName.lastIndexOf(".");
  109.   if (index != -1)
  110.     retVal = fileName.substring(0,index);
  111.   return retVal;
  112. }